#include "QueryProcessor.h"


QueryProcessor::QueryProcessor()
{
	this->_evaluator.SetQueryPreprocessor( &this->_preprocessor );
}

QueryProcessor::~QueryProcessor()
{

}

void QueryProcessor::PreparePreprocessor()
{
	this->_preprocessor.calculateHeuristicsValue();
}

std::list<std::string> QueryProcessor::Process( std::string query )
{
	query_tree tree;
	bool parsed = this->_parser.Parse( query, tree );

	if ( !parsed )
	{
		std::list<std::string> error;
		error.push_back( "Parsing error." );
		return error;
	}

	bool valid = this->_validator.Validate( tree );

	if ( !valid )
	{
		return this->_validator.GetErrors();
	}

	this->_preprocessor.Preprocess( tree );

	return this->_evaluator.Evaluate( tree );
}